package com.mdd.admin.controller.service;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.service.IAnnualServiceService;
import com.mdd.admin.validate.service.AnnualServiceParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.service.AnnualServiceListVo;
import com.mdd.admin.vo.service.AnnualServiceDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 包年服务使用记录管理
 */
@RestController
@RequestMapping("api/service")
public class AnnualServiceController {

    @Resource
    IAnnualServiceService iAnnualServiceService;

    /**
     * 获取包年服务的记录数据
     *
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<AnnualServiceListVo> list = iAnnualServiceService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 包年服务使用记录详情
     *
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        AnnualServiceDetailVo detail = iAnnualServiceService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 包年服务使用记录新增
     *
     * @param annualServiceParam 参数
     * @return Object
     */
    @Log(title = "包年服务使用记录新增")
    @PostMapping("/add")
    public Object add(@Validated(value = AnnualServiceParam.create.class) @RequestBody AnnualServiceParam annualServiceParam) {
        iAnnualServiceService.add(annualServiceParam);
        return AjaxResult.success();
    }

    /**
     * 包年服务使用记录编辑
     *
     * @param annualServiceParam 参数
     * @return Object
     */
    @Log(title = "包年服务设置已完成")
    @PostMapping("/edit")
    public Object edit(@Validated(value = AnnualServiceParam.update.class) @RequestBody AnnualServiceParam annualServiceParam) {
        iAnnualServiceService.edit(annualServiceParam);
        return AjaxResult.success();
    }

    /**
     * 包年服务使用记录删除
     *
     * @param annualServiceParam 参数
     * @return Object
     */
    @Log(title = "包年服务使用记录删除")
    @PostMapping("/del")
    public Object del(@Validated(value = AnnualServiceParam.delete.class) @RequestBody AnnualServiceParam annualServiceParam) {
        iAnnualServiceService.del(annualServiceParam.getId());
        return AjaxResult.success();
    }

}
